package cn.iocoder.yudao.module.erp.service.payrecord;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.erp.controller.admin.payrecord.vo.*;
import cn.iocoder.yudao.module.erp.dal.dataobject.payrecord.PayRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.erp.dal.mysql.payrecord.PayRecordMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;

/**
 * 付款记录 Service 实现类
 *
 * @author mhc
 */
@Service
@Validated
public class PayRecordServiceImpl implements PayRecordService {

    @Resource
    private PayRecordMapper payRecordMapper;

    @Override
    public Long createPayRecord(PayRecordSaveReqVO createReqVO) {
        // 插入
        PayRecordDO payRecord = BeanUtils.toBean(createReqVO, PayRecordDO.class);
        payRecordMapper.insert(payRecord);
        // 返回
        return 0L;
    }

    @Override
    public void updatePayRecord(PayRecordSaveReqVO updateReqVO) {
        // 校验存在
        validatePayRecordExists(0L);
        // 更新
        PayRecordDO updateObj = BeanUtils.toBean(updateReqVO, PayRecordDO.class);
        payRecordMapper.updateById(updateObj);
    }

    @Override
    public void deletePayRecord(Long id) {
        // 校验存在
        validatePayRecordExists(id);
        // 删除
        payRecordMapper.deleteById(id);
    }

    private void validatePayRecordExists(Long id) {
        if (payRecordMapper.selectById(id) == null) {
            throw exception(PAY_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public PayRecordDO getPayRecord(Long id) {
        return payRecordMapper.selectById(id);
    }

    @Override
    public PageResult<PayRecordDO> getPayRecordPage(PayRecordPageReqVO pageReqVO) {
        return payRecordMapper.selectPage(pageReqVO);
    }

}